home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / prtinfo / prtinfo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  2.1 KB  |  63 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Device name and port"
  4.    ClientHeight    =   975
  5.    ClientLeft      =   1080
  6.    ClientTop       =   1650
  7.    ClientWidth     =   7485
  8.    Height          =   1380
  9.    Left            =   1020
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   975
  12.    ScaleWidth      =   7485
  13.    Top             =   1305
  14.    Width           =   7605
  15.    Begin Label Label1 
  16.       AutoSize        =   -1  'True
  17.       Caption         =   "Label1"
  18.       Height          =   195
  19.       Left            =   360
  20.       TabIndex        =   0
  21.       Top             =   300
  22.       Width           =   585
  23.    End
  24. '... This function converts a windows API LPstring to a VB string.
  25. Function FixAPIString$ (ByVal test$)
  26.   FixAPIString$ = Trim(Left$(test$, InStr(test$, Chr$(0)) - 1))
  27. End Function
  28. Sub Form_Load ()
  29.   Dim dev$, devname$, devoutput$
  30.   dev$ = GetDefPrinter$() ' Get default printer info
  31.   If dev$ = "" Then GoTo jump1
  32.   devname$ = GetDeviceName$(dev$)' Strip the device name from dev$
  33.   devoutput$ = GetDeviceOutput$(dev$)' Strip the device port from dev$
  34.   label1.Caption = devname$ + " on  " + devoutput$
  35.   GoTo jump2
  36. jump1:
  37.   label1.Caption = "No device found"
  38. jump2:
  39. End Sub
  40. '  This function retrieves the definition of the default
  41. '  printer on this system contained in the win.ini file.
  42. Function GetDefPrinter$ ()
  43.     Dim def$
  44.     def$ = String$(128, 0)
  45.     di% = GetProfileString%("windows", "device", "", def$, Len(def$))
  46.     def$ = FixAPIString$(def$)
  47.     GetDefPrinter$ = def$
  48. End Function
  49. '   Retrieves the name portion of a device string.
  50. Function GetDeviceName$ (dev$)
  51.     Dim npos%
  52.     npos% = InStr(dev$, ",")
  53.     GetDeviceName$ = Left$(dev$, npos% - 1)
  54. End Function
  55. '   Returns the output destination for the specified
  56. '   device.
  57. Function GetDeviceOutput$ (dev$)
  58.     Dim firstpos%, nextpos%
  59.     firstpos% = InStr(dev$, ",")
  60.     nextpos% = InStr(firstpos% + 1, dev$, ",")
  61.     GetDeviceOutput$ = Mid$(dev$, nextpos% + 1)
  62. End Function
  63.